import { _circle, _rect, _line, _text } from './svg.js'
import { patternMap } from './pattern/index.js'
import { axisMap } from './axis/index.js'
import { fractalMap } from './fractal/index.js'
import { _polygon, _triangle, _ray, _square, _pentagon, _hexagon, _heptagon } from './polygon.js'
import { _star } from './star.js'
import { _spiral, _twoSpiral } from './spiral.js'
import { _maze } from './maze.js'
import { _gridRect, _gridPolygon } from './gridRect.js'
import { spiralShape, ringShape, rayShape, gridShape, isometricShape, polygonShape } from './polarShape.js'
import { iconsMap } from './icon.js'
import { lsystem } from './lsystem.js'
import { _oneline } from './oneline.js'
import { polarPoints, polarGridPoints } from '../algorithm/polar.js'
import { spiralPoints } from '../algorithm/polarMatrix.js'
import { gridCrossPoints, gridCellPoints } from '../algorithm/grid.js'
import { _koch } from './koch.js'
import { _sierpinski, _sierpinskiBezier } from './sierpinski.js'
import { _peano } from './peano.js'
import {_gougu} from './gougu.js'


// 图形函数
export const shapeFnMap = {
    circle: _circle,
    rect: _rect,
    line: _line,
    polygon: _polygon,
    star: _star,
    ray: _ray,
    text: _text,
    triangle: _triangle,
    square: _square,
    pentagon: _pentagon,
    hexagon: _hexagon,
    heptagon: _heptagon,
    spiral: _spiral,
    maze: _maze,
    gridRect: _gridRect,
    gridPolygon: _gridPolygon,
    twoSpiral: _twoSpiral,
    polarShape: _oneline, // 镜像函数升级，支持一笔画
    spiralShape,
    ringShape,
    rayShape,
    gridShape,
    isometricShape,
    polygonShape,
    lsystem,
    lsystemPlant: lsystem,
    oneline: _oneline,
    ...fractalMap,
    ...axisMap,
    ...patternMap,
    ...iconsMap,
    koch: _koch,
    sierpinski: _sierpinski,
    sierpinskiBezier: _sierpinskiBezier,
    peano: _peano,
    gougu:_gougu
}

// 点阵函数
export const pointsFnMap = {
    gridCrossPoints,
    gridCellPoints,
    polarPoints, polarGridPoints, spiralPoints,
}

export const patternTypes = Object.keys(patternMap)
export const shapeTypes = Object.keys(shapeFnMap)




export const checkRegisteredShape = (shape) => {
    return !!shapeFnMap[shape]
}

export const renderRegisteredShape = (shape, options, props) => {
    return shapeFnMap[shape](options, props)
}

export const checkRegisteredPoints = (shape) => {
    return !!pointsFnMap[shape]
}

export const renderRegisteredPoints = (shape, options, props) => {
    let points = pointsFnMap[shape](options, props)
    return renderPath(points, options, props)
}

export const renderRegistry = (shape, options, props) => {
    if (checkRegisteredShape(shape)) {
        return renderRegisteredShape(shape, options, props)
    } else if (checkRegisteredPoints(shape)) {
        return renderRegisteredPoints(shape, options, props)
    }
}